package Datatypes;

import java.io.Serializable;
import java.security.MessageDigest;

public class MD5 implements Serializable{

    public MD5() {}
   
    public String md5(String clear) throws Exception {
    
        MessageDigest md = MessageDigest.getInstance("MD5");
    
        byte[] b = md.digest(clear.getBytes());

        int size = b.length;
    
        StringBuilder h = new StringBuilder(size);
    
        for (int i = 0; i < size; i++) {
    
            int u = b[i] & 255;
    
            if(u < 16) {
    
                h.append("0").append(Integer.toHexString(u));
    
            } 
            
            else{
    
                h.append(Integer.toHexString(u));
    
            }
    
        }
    
        return h.toString();
    
    }
    
}
